package edu.sctu.zhoudie.mouth201505.day20150517.TextThree;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Random;

/**
 * Created by user08 on 2015/5/17.
 */
public class Collection {
    public String name;
    public void sortsCollection(){
        List<Integer> integers = new ArrayList<Integer>();

        Random random = new Random();

        for (int i = 0; i < 10; i++) {

            Integer k;
            do {
                k = random.nextInt(100);

            } while (integers.contains(k));

            integers.add(k);
            System.out.println("成功添加整数：" + k);

        }


        System.out.println("*****排序前*****");
        for (Integer integer : integers){

            System.out.println(integer);

        }

        Collections.sort(integers);

        System.out.println("*****排序后*****");

        for (Integer integer : integers){

            System.out.println(integer);

        }
    }

    public void sort2(){

        List<String> stringslist = new ArrayList<String>();
        for (int i = 0; i < 10; i++) {
            stringslist.add("leoven"+i);
        }

        System.out.println("*****排序前*****");
        for(String s : stringslist){
            System.out.println("元素："+s);

        }
        Collections.sort(stringslist);
        System.out.println("*****排序后*****");
        for(String s : stringslist){
            System.out.println("元素："+s);

        }
    }

    public void sort3(){
        List<Student> list = new ArrayList<>();

        list.add(new Student(1+"","xiangkun"));
        list.add(new Student(5+"","zcy"));
        list.add(new Student(3+"","zhoudie"));

        System.out.println("*****排序前*****");
        for(Student s : list){
            System.out.println("学生："+s.name);

        }

        Collections.sort(list);

        System.out.println("*****排序后*****");
        for(Student s : list){
            System.out.println("元素："+s.name);

        }
        Collections.sort(list,new Comparetor());
        System.out.println("*****按姓名排序后*****");
        for(Student s : list){
            System.out.println("元素："+s.name);

        }



    }

    public static void main(String[] args) {
        Collection collection = new Collection();

        collection.sortsCollection();
        collection.sort2();
        collection.sort3();
    }
}
